{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "67110919-5790-43c9-9f7b-bc4b12f8da5b",
   "metadata": {},
   "source": [
    "# 第三节课读书笔记 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdd32389-1dbd-40e3-8847-00d814f1b170",
   "metadata": {},
   "source": [
    "## Python变量的命名法\n",
    "Python中取变量的名字：字母+数字+\"__\"三类组成；首字不能为数字；不能与“保留字”相同。\n",
    "在未来的编程中有如下要求：\n",
    " * 尽可能不要用i，j，k这样的无意义的变量名称；\n",
    " * 尽可能使用英文表示变量的含义，score等；\n",
    " * 如果有多个单词组成的变量，用下划线___连接。\n",
    "\n",
    " * 程序代码示例：\n",
    "           \n",
    "         i = 1\n",
    "         print (i)\n",
    "* * *"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3c1e686e-2bf6-4a8f-b170-1b70dbed3120",
   "metadata": {},
   "source": [
    "## Python变量的类型(Variable Type)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b16b4104-05ca-4df8-b3ae-75c59b07eb74",
   "metadata": {},
   "outputs": [],
   "source": [
    "Python 变量的类型分为3类:\n",
    "\n",
    "* 数值型:(digital) : Bool,int,float,complex\n",
    "* 字符型:(string): str\n",
    "* 空: None       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "55d35930-bf89-4289-9933-619f032ea6ef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n",
      "牢大\n"
     ]
    }
   ],
   "source": [
    "x=24\n",
    "x=\"牢大\"\n",
    "print(type(x))\n",
    "print(x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "c85d7eb9-772b-482b-bfe3-b93eddb4bc5c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isinstance(x,float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "56a79ab6-27cb-429c-ab93-f16f39233aa1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 1\n"
     ]
    }
   ],
   "source": [
    "a = '1'\n",
    "b = 1 \n",
    "print(a,b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "deca7014-31aa-4ff5-bf15-c12855dc5b89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a == b"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca69fd4d-4de8-4bae-ac44-5941ded0ca00",
   "metadata": {},
   "source": [
    "## Python的运算符"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "377b72cb-f8d4-447f-b9d2-a0fab6f9a257",
   "metadata": {
    "scrolled": true
   },
   "source": [
    "-   数值计算:     + , - ,  * ,  / ,  ** ,  % ,  // ,  += ,  -= ,  /=\n",
    "-  字符串运算符: + ,  *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "8a6f8ebb-def5-49e4-b45a-8184fe437886",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 1\n",
    "a += 2\n",
    "a = a + 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "54605f75-472c-4901-8b80-eb8147f1e6ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "a = 3 & 4 \n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "1fb9f493-6066-45a6-881b-48b4193ba780",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n"
     ]
    }
   ],
   "source": [
    "a = 6 & 4\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "6d42d3b8-7455-4d5a-917a-a29568a0696b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 二进制：\n",
    "#    0 = 0000\n",
    "#    1 = 0001\n",
    "#    2 = 0010\n",
    "#    3 = 0011\n",
    "#    4 = 0100"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b3b3485e-9ab5-4fb6-a9ce-d2baa12d8f4f",
   "metadata": {},
   "source": [
    "## Python变量的拓展"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "560bcbd7-f595-45d2-844c-6e4768bd2105",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "<class 'int'>\n"
     ]
    }
   ],
   "source": [
    "a = True\n",
    "b = 2\n",
    "c = a + b\n",
    "print(c)\n",
    "print(type(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "599b7068-6d22-4d08-9a69-c486196b56a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0 == False"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "442cc958-d41c-496e-bbea-acecd742fa11",
   "metadata": {},
   "source": [
    "## Python字符串函数与切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "864e1c1a-ce78-4ce6-85bd-8db89c91ce31",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = \"Guangzhou University\"\n",
    "len(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "1001d526-40b4-4cf7-95e3-e5cb37057d20",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"zhou\" in a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "id": "f9807da5-4227-4619-a55f-7d6d91bedcd3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "00\n",
      "22\n",
      "37.0\n",
      "0.3769444444444444\n"
     ]
    }
   ],
   "source": [
    "b = \"10\t \t*\t00 22 37.0\t2\t+63 52.0\t2\t110.0\t17.0\t \t5.4\t00 25 25.1\t+64 08 36\"\n",
    "test1 = b[7:9]\n",
    "test2 = b[10:12]\n",
    "test3 = b[13:17]\n",
    "print(test1) #deg\n",
    "print(test2) #minute\n",
    "print(test3) #sec\n",
    "print(eval(test1)+ eval(test2)/60 + eval(test3)/3600.)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c42fbcf0-4974-45fc-bacc-a1ea4c212735",
   "metadata": {},
   "source": [
    "## Python的格式化输出\n",
    "格式化输出有3种技术\n",
    "\n",
    "- %\n",
    "- format\n",
    "- fString\n",
    "  \n",
    "  \"格式化说明\" %  (要显示输出的变量)\n",
    "      %d , %f , %s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "id": "28814ebb-6e75-4f51-b125-6aefbbbfb67d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.14159265358979\n"
     ]
    }
   ],
   "source": [
    "pi = 3.14159265358979\n",
    "print(pi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "id": "a939bd0a-f3ff-481b-830a-d6f660ef4fe0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  3.1416\n",
      "   3   4\n",
      "00030004\n"
     ]
    }
   ],
   "source": [
    "a = 3\n",
    "b = 4\n",
    "c = 100\n",
    "pi = 3.14159265358979\n",
    "print(\"%8.4f\" % pi)\n",
    "print(\"%4d%4d\" % (a,b))\n",
    "print(\"%04d%04d\" % (a,b))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "id": "4a7eb1cf-0d24-46c8-a62b-8f47335cf779",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.7195822853010423\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "print(random.random())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 286,
   "id": "44ed81db-316e-4b53-8442-d9986bb3e9fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   79.81   94.52   26.89   51.88   19.65   64.62   47.58   97.41   89.04   56.02\n",
      "   67.10   74.78   38.76   91.74    3.48    2.62    3.64   36.04   97.09   64.08\n",
      "   94.14   38.72   95.30   85.94   96.79   42.25   62.01   14.48   55.54   47.75\n",
      "   73.09   48.43   70.90   52.52    9.71   24.87   19.42   12.25   77.31   51.24\n",
      "   87.56   71.43   11.67   98.37   59.93   32.96   28.00    4.65   29.82   66.74\n",
      "   83.75    5.62   60.82   23.16   14.75   39.45   67.04   15.42    1.43   39.17\n",
      "   78.18   46.43   80.94   88.34   12.04   60.95   43.71   32.06   28.54   32.83\n",
      "   96.30   20.62   36.47   50.94   19.35   69.14   93.07   28.16   64.51    4.55\n",
      "   18.99   23.03   73.02   73.67   33.72   17.51   35.30   52.09   80.17   23.35\n",
      "   38.17   44.37    3.78   15.64   14.28   24.58   42.44   92.61   30.61   59.84\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "for s in range(100):\n",
    "    i = random.uniform(0,100)\n",
    "    print(\"%8.2f\" % i,end =\"\")\n",
    "    if (s + 1) % 10 == 0 :\n",
    "        print()\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5d08380d-1973-44a1-8302-ea2524dbe071",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38302afa-59c7-445e-a772-f1d45e879a45",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bde18d1d-3276-4147-ab0e-2bc46f3c7c88",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0677cbfb-6828-46e7-8c0e-b5c75edfc296",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8034b6a6-0bbe-4fea-b76a-c702887d96db",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "788395f1-eb45-4db0-a088-874363c85c5f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d7aba032-6e4e-4ccf-badb-cf6c8ec31aff",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
